import java.util.Random;

public class ThreadDemo {



    private static class MyThread extends Thread{
        @Override
        public void run(){
            Random random = new Random();
            while(true){
                //打印线程名
                System.out.println(Thread.currentThread().getName());
                try {
                    //随机停止运行0-9秒
                    Thread.sleep(random.nextInt(10));
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
    public static void main(String[] args) {
        MyThread t1 = new MyThread();
        MyThread t2 = new MyThread();
        MyThread t3 = new MyThread();
        t1.start();
        t2.start();
        t3.start();
        Random random = new Random();
        while(true){
            //打印main线程的名称
            System.out.println(Thread.currentThread().getName());
            try {
                //随机停止运行0-9秒
                Thread.sleep(random.nextInt(10));
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
